package com.baor.web.controller.vip;

import com.baor.common.core.domain.R;
import com.baor.common.core.page.TableDataInfo;
import com.baor.common.utils.file.FileUploadUtils;
import com.baor.vip.domain.*;
import com.baor.vip.service.*;
import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 会员Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/vip/vip")
public class VipController extends BaseController
{
    @Autowired
    private VipService vipService;
    @Autowired
    private TagService tagService;
    @Autowired
    private ScoreService scoreService;
    @Autowired
    private BlackService blackService;
    @Autowired
    private BrokerService brokerService;
    @Autowired
    private RechargeService rechargeService;
    @Autowired
    private RefundService refundService;
    @Autowired
    private CarService carService;


    /**
     * 查询会员列表
     */
//    @PreAuthorize("@ss.hasPermi('vip:vip:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody VipVO tVip)
    {
        startPage();
        List<VipVO> list = vipService.selectTVipList(tVip);
        return getDataTable(list);
    }

    /**
     * 获取会员详细信息
     */
//    @PreAuthorize("@ss.hasPermi('vip:vip:query')")
    @GetMapping(value = "/{vipUid}")
    public R getInfo(@PathVariable("vipUid") Integer vipUid)
    {
        return vipService.selectTVipByVipUid(vipUid);
    }

    /**
     * 新增会员
     */
//    @PreAuthorize("@ss.hasPermi('vip:vip:add')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping("/addVip")
    public R addVip(@RequestBody VipVO tVip)
    {
        return vipService.insertVipVO(tVip);
    }

    /**
     * 修改会员
     */
//    @PreAuthorize("@ss.hasPermi('vip:vip:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping("/updateVip")
    public R edit(@RequestBody VipVO tVip)
    {
        return vipService.updateVipVO(tVip);
    }

    /**
     * 删除会员
     */
//    @PreAuthorize("@ss.hasPermi('vip:vip:remove')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("delVip/{vipUids}")
    public AjaxResult remove(@PathVariable Integer[] vipUids)
    {
        return toAjax(vipService.deleteVipVOByVipUids(vipUids));
    }


    //会员标签下拉框
//    @PreAuthorize("@ss.hasPermi('vip:vip:tagList')")
    @GetMapping("/tagBox")
    public R tagBox()
    {
        List<TagVO> list = vipService.selectTagList();
        return R.ok(list);
    }
    //会员来源下拉框
//    @PreAuthorize("@ss.hasPermi('vip:vip:vipOriginBox')")
    @GetMapping("/vipOriginBox")
    public R vipOriginBox()
    {
        List<String> list = vipService.vipOriginBox();
        return R.ok(list);
    }

    //会员详情积分修改
    //    @PreAuthorize("@ss.hasPermi('vip:vip:vipScoreUpdate')")
    @PostMapping("/vipScoreUpdate")
    public R vipScoreUpdate(@RequestBody ScoreChangeVO scoreChangeVO)
    {
        return R.ok(scoreService.addScore(scoreChangeVO));
    }
    //会员详情余额修改
    //    @PreAuthorize("@ss.hasPermi('vip:vip:vipBlackUpdate')")
    @PostMapping("/vipBlackUpdate")
    public R vipBlackUpdate(@RequestBody BlackChangeVO blackChangeVO)
    {
        return R.ok(blackService.addBlack(blackChangeVO));
    }

    /**
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     * --------------------------------------------------------------标签
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     */
    /**
     * 查询会员标签列表
     */
//    @PreAuthorize("@ss.hasPermi(':tag:list')")
    @PostMapping("/tagList")
    public TableDataInfo tagList(@RequestBody TagVO tTag)
    {
        startPage();
        List<TagVO> list = tagService.selectTagVOList(tTag);
        return getDataTable(list);
    }
    /**
     * 新增会员标签
     */
//    @PreAuthorize("@ss.hasPermi('system:tag:add')")
    @Log(title = "会员标签", businessType = BusinessType.INSERT)
    @PostMapping("addTag")
    public AjaxResult addTag(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.insertTagVO(tTag));
    }

    /**
     * 修改会员标签
     */
//    @PreAuthorize("@ss.hasPermi('system:tag:edit')")
    @Log(title = "会员标签", businessType = BusinessType.UPDATE)
    @PutMapping("updateTag")
    public AjaxResult updateTag(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.updateTagVO(tTag));
    }

    /**
     * 删除会员标签
     */
//    @PreAuthorize("@ss.hasPermi('system:tag:remove')")
    @Log(title = "会员标签", businessType = BusinessType.DELETE)
    @DeleteMapping("removeTag/{tagIds}")
    public AjaxResult removeTag(@PathVariable Integer[] tagIds)
    {
        return toAjax(tagService.deleteTagVOByTagIds(tagIds));
    }


    /**
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     * --------------------------------------------------------------积分
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     */
    /**
     * 查询会员积分列表
     */
//    @PreAuthorize("@ss.hasPermi('system:score:scoreList')")
    @PostMapping("/scoreList")
    public R scoreList(@RequestBody ScoreChangeDTO scoreChangeDTO)
    {
        Map<String,Object> list = scoreService.selectScoreVOList(scoreChangeDTO);
        return R.ok(list);
    }
    /**
     * 查询会员积分下拉框
     */
    //    @PreAuthorize("@ss.hasPermi('system:score:scoreList')")
    @GetMapping("/scoreOrginBox")
    public R scoreOrginBox()
    {
        return R.ok(scoreService.scoreOrginBox());
    }
    /**
     * 新增会员积分变列
     */
//    @PreAuthorize("@ss.hasPermi('system:score:add')")
    @Log(title = "会员积分", businessType = BusinessType.INSERT)
    @PostMapping("addScore")
    public R addScore(@RequestBody ScoreChangeVO scoreChangeVO)
    {
        return R.ok(scoreService.addScore(scoreChangeVO) == 1 ?"成功":"失败");
    }

    /**
     * 修改会员积分 --没写
     */
//    @PreAuthorize("@ss.hasPermi('system:score:edit')")
    @Log(title = "会员积分", businessType = BusinessType.UPDATE)
    @PutMapping("updateScore")
    public AjaxResult updateScore(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.updateTagVO(tTag));
    }

    /**
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     * --------------------------------------------------------------余额
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     */
    /**
     * 查询会员余额列表
     */
//    @PreAuthorize("@ss.hasPermi('system:black:blackList')")
    @PostMapping("/blackList")
    public R blackList(@RequestBody BlackChangeDTO blackChangeDTO)
    {
        startPage();
        Map<String,Object> list = blackService.selectBlackVOList(blackChangeDTO);
        return R.ok(list);
    }
    /**
     * 查询会员余额来源下拉框
     */
    //    @PreAuthorize("@ss.hasPermi('system:black:blackOrginBox')")
    @GetMapping("/blackOrginBox")
    public R blackOrginBox()
    {
        return R.ok(blackService.blackOrginBox());
    }
    /**
     * 查询会员余额账号类型下拉框
     */
    //    @PreAuthorize("@ss.hasPermi('system:black:blackTypeBox')")
    @GetMapping("/accTypeBox")
    public R accTypeBox()
    {
        return R.ok(blackService.accTypeBox());
    }
    /**
     * 新增会员余额
     */
//    @PreAuthorize("@ss.hasPermi('vip:black:add')")
    @Log(title = "会员余额", businessType = BusinessType.INSERT)
    @PostMapping("addBlack")
    public R addBlack(@RequestBody BlackChangeVO blackChangeVO)
    {
        return R.ok(blackService.addBlack(blackChangeVO) == 1 ? "成功": "失败");
    }

    /**
     * 修改会员余额  --没写
     */
//    @PreAuthorize("@ss.hasPermi('system:black:edit')")
    @Log(title = "会员余额", businessType = BusinessType.UPDATE)
    @PutMapping("updateBlack")
    public AjaxResult updateBlack(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.updateTagVO(tTag));
    }


    /**
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     * --------------------------------------------------------------佣金
     * ++++++++++++++++++++++++++++++++++++++++++++++++++++
     */
    /**
     * 查询会员佣金列表
     */
//    @PreAuthorize("@ss.hasPermi('system:broker:brokerList')")
    @PostMapping("/brokerList")
    public R brokerList(@RequestBody BrokerChangeDTO brokerChangeDTO)
    {
        startPage();
        Map<String,Object> list = brokerService.selectBrokerVOList(brokerChangeDTO);
        return R.ok(list);
    }
    /**
     * 查询会员佣金来源下拉框
     */
    //    @PreAuthorize("@ss.hasPermi('system:broker:brokerOrginBox')")
    @GetMapping("/brokerOrginBox")
    public R brokerOrginBox()
    {
        return R.ok(brokerService.brokerOrginBox());
    }

    /**
     * 新增会员佣金     --没写
     */
//    @PreAuthorize("@ss.hasPermi('system:broker:add')")
    @Log(title = "会员佣金", businessType = BusinessType.INSERT)
    @PostMapping("addBroker")
    public AjaxResult addBroker(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.insertTagVO(tTag));
    }

    /**
     * 修改会员佣金  --没写
     */
//    @PreAuthorize("@ss.hasPermi('system:broker:edit')")
    @Log(title = "会员佣金", businessType = BusinessType.UPDATE)
    @PutMapping("updateBroker")
    public AjaxResult updateBroker(@RequestBody TagVO tTag)
    {
        return toAjax(tagService.updateTagVO(tTag));
    }
/**
 *
 *
 *
 * ---------------------应用应用应用应用
 *
 *
 *
 */
//列表
//    @PreAuthorize("@ss.hasPermi('system:recharge:orderList')")
    @PostMapping("/orderList")
    public R orderList(@RequestBody RechargeVO rechargeVO)
    {
        startPage();
        Map<String,Object> list = rechargeService.orderList(rechargeVO);
        return R.ok(list);
    }

//    来源下拉框
//    @PreAuthorize("@ss.hasPermi('system:recharge:originBox')")
    @GetMapping("/originBox")
    public R originBox() {

        List<String> list = rechargeService.originBox();
        return R.ok(list);
    }
//    类型下拉框
//    @PreAuthorize("@ss.hasPermi('system:recharge:originBox')")
    @GetMapping("/orderTypeBox")
    public R orderTypeBox() {

        Map<Integer,String> list = new HashMap<>();
        list.put(0,"待支付");
        list.put(1,"已支付");
        list.put(2,"已退款");
        return R.ok(list);
    }

    /**
     * -------------------------退款记录
     * @param refundVO
     * @return
     */
    //列表
//    @PreAuthorize("@ss.hasPermi('system:refund:redundList')")
    @PostMapping("/redundList")
    public R redundList(@RequestBody RefundVO refundVO)
    {
        startPage();
        Map<String,Object> list = refundService.redundList(refundVO);
        return R.ok(list);
    }

    //    来源下拉框
//    @PreAuthorize("@ss.hasPermi('system:refund:payTypeBox')")
    @GetMapping("/payTypeBox")
    public R payTypeBox() {

        Map<Integer,String> list = new HashMap<>();
        list.put(0,"微信");
        list.put(1,"支付宝");
        list.put(2,"公众号");
        return R.ok(list);
    }
    //    类型下拉框
//    @PreAuthorize("@ss.hasPermi('system:refund:statusBox')")
    @GetMapping("/statusBox")
    public R statusBox() {

        Map<Integer,String> list = new HashMap<>();
        list.put(0,"待审核");
        list.put(1,"已退款");
        list.put(2,"未退款");
        return R.ok(list);
    }

    /**
     * &&&&&&&&&&&&&&&&&&&&______上传图片-------
     */
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws IOException {
        String url = FileUploadUtils.upload(file);
//        System.out.println("vipIcon"+url);
        return AjaxResult.success("上传成功", url);
    }

    /**
     *             ||
     */

    @PostMapping("/userInfo")
    public AjaxResult userInfo(Integer vipUid){
        return AjaxResult.success(vipService.userInfo(vipUid));
    }

    ///购物车模块
    @PostMapping("/carAdd")
    public R carAdd(@RequestBody CarVO carVO){
        return carService.carAdd(carVO);
    }
    @GetMapping("/carList")
    public R carList(Integer vipUid){
        return carService.carList(vipUid);
    }
    //修改数量
    @PostMapping("/goodsNum")
    public R goodsNum(@RequestBody Map<String,Integer> map){
        return carService.goodsNum(map);
    }
    //删除
    @DeleteMapping("delCar/{carIds}")
    public R delCar(@PathVariable Integer[] carIds)
    {
        return carService.delCar(carIds);
    }
    //结算?
}
